import Vue from 'vue'

let page = {
  total: 1,
  startIndex: 0,
  stepNumber: 60,
  currentPage: 1
};

let data={
  productList:[],
  categoryList:[]
};

let status={
  actionModal:{
    isShow:false,
    isLoading:false,
    title:'',
    content:'',
    action:'',
    productId:'',
    productCode:''
  },
  //查看图片
  modalImage: {
    isShow: false,
    url: ''
  },
};
let params={
  operation:"0",
  productCode:'',
  selectedClassification:'',
  classificationLevel :"0",
  orderBy:""
};
let  tableTitles=function (self) {
  let titles =  [
    {
      title: '#',
      type: 'index',
      width: 55,
      align: 'center'
    },
    {
      title: 'SKU',
      key: 'code',
      width: 120,
      align: 'center',
      render: (h, params) => {
        let productUrl = Vue.prototype.$tiyProductUrl(params.row.code);
        return h('div',[h('a',{
          attrs:{href:productUrl,target:'_blank'}
        },params.row.code)]);
      }
    },
    {
      title: '产品名',
      key: 'name',
      align: 'left',
      minWidth:300,
    },
    {
      title: '产品图片',
      key: 'productImg',
      width: 120,
      render: (h, params) => {
        let imageUrl = params.row.productImg;
        let bigImg = params.row.productImg;
        if(params.row.productShowImg!=null&&params.row.productShowImg.zipImgs!=null){
          let zipImg = params.row.productShowImg.zipImgs;
          zipImg.forEach(function (item){
            if(item.size=="200w"){
              imageUrl=self.yunPath+item.imagePath;
            }
          })
        }

        return '' === imageUrl||imageUrl===null ? '' : h('img', {
          attrs: {src: imageUrl, height: 60},
          on: {
            click: () => {
              status.modalImage.url = bigImg;
              status.modalImage.isShow = true;
            }
          }
        })
      },
      align: 'center'
    },
    {
      title: '价格($)',
      key: 'currentPrice',
      width: 100,
      align: 'center'
    },
    {
      title: '销量',
      key: 'sale_count',
      width: 100,
      align: 'center',
      render: (h, params) => {
        return h('div', params.row.saleCount)
      }
    },
    {
      title: '订单数',
      key: 'orderCount',
      width: 100,
      align: 'center'
    },
    {
      title: '删除时间',
      key: 'lastmodify',
      sortable: 'custom',
      width: 120,
      render: (h, params) => {
        return h('div', self.$tiyBJTime(params.row.lastmodify));
      },
      align: 'center'
    },
   {
      title: '操作',
      key: 'action',
      width: 180,
      align: 'center',
      render: (h, params) => {
        return h('div', [
            !self.$authority('PRODUCT-7-201')?null:h('Button', {
            props: {type: 'primary', size: 'small', icon: "md-return-left",},
            style: {marginRight: '10px'},
            on: {
              click: () => {
                self.findBackProduct(params.row.id, params.row.code);
              }
            }
          }, "找回"),
            !self.$authority('PRODUCT-7-202')?null:h('Button', {
            props: {type: 'error', size: 'small', icon: "md-trash",},
            on: {
              click: () => {
                self.delete(params.row.id, params.row.code);
              }
            }
          }, "删除 "),
        ]
      )},
    }
  ];

  return self.$authTableTitles(titles)
};

export  default  {
  tPage: page,
  tStatus: status,
  tParam: params,
  tData: data,
  listTableTitles:tableTitles,
};
